jQuery(function($){
    var user;
    var uuid;
    var $lefttop=$("#lefttop");
    function getcookie(){
        uuid = jq.cookie("login");
        $.ajax({
            url:"/loginget",
            data:{
                "uuid":uuid,
            },
            success:function(data){
                if(data!=null && data !=""){
                    $lefttop.empty();
                    //头部信息
                    $lefttop.append($("<span class='fl'>欢迎&nbsp;"+data.loginname+"&nbsp;</span>").append($("<a href='Member_Order.html'>&nbsp;我的订单&nbsp;|</a>")).
                    append($("<a href='javascript:void(0);' id='loginout'>注销&nbsp;|</a>").click(function(){
                        $.ajax({
                            url:"/loginout",
                            data:{
                                "uuid":uuid,
                            },
                            success:function (data){
                                window.location="login.html"
                            }
                        })
                    }))).append('<span class="ss">\n' +
                        '                <div class="ss_list">\n' +
                        '                \t<a href="#">客户服务</a>\n' +
                        '                    <div class="ss_list_bg">\n' +
                        '                    \t<div class="s_city_t"></div>\n' +
                        '                        <div class="ss_list_c">\n' +
                        '                        \t<ul>\n' +
                        '                            \t<li><a href="#">客户服务</a></li>\n' +
                        '                                <li><a href="#">客户服务</a></li>\n' +
                        '                                <li><a href="#">客户服务</a></li>\n' +
                        '                            </ul>\n' +
                        '                        </div>\n' +
                        '                    </div>    \n' +
                        '                </div>\n' +
                        '                <div class="ss_list">\n' +
                        '                \t<a href="#">网站导航</a>\n' +
                        '                    <div class="ss_list_bg">\n' +
                        '                    \t<div class="s_city_t"></div>\n' +
                        '                        <div class="ss_list_c">\n' +
                        '                        \t<ul>\n' +
                        '                            \t<li><a href="#">网站导航</a></li>\n' +
                        '                                <li><a href="#">网站导航</a></li>\n' +
                        '                            </ul>\n' +
                        '                        </div>\n' +
                        '                    </div>    \n' +
                        '                </div>\n' +
                        '            </span>\n' +
                        '                <span class="fl">|&nbsp;关注我们：</span>\n' +
                        '                <span class="s_sh"><a href="#" class="sh1">新浪</a><a href="#" class="sh2">微信</a></span>\n' +
                        '                <span class="fr">|&nbsp;<a href="#">手机版&nbsp;<img src="images/s_tel.png" align="absmiddle" /></a></span>\n' +
                        '            </span>');
                }
            }
        })
    }
    getcookie();


    function init(){
        var $ul =$(".menu_r");
        var $leftzuo = $("#leftzuo");
        var map;
        $.ajax({
            url:"/Product/selectAll",
            data:{},
            success:function (data){
                //导航栏上
                $ul.empty();
                $ul.prepend($("<li><a href='index.html'>首页</a></li>"))
                $.each(data.listcate,function(index,category){
                    if(category.type==1){
                        var $li = $("<li></li>")
                        var $a = $("<a href='javascript:void(0)'>"+category.name+"</a>")
                        $li.append($a);
                        $ul.append($li);
                    }
                })
                //导航栏左
                $leftzuo.empty();
                var $int = 1;
                $.each(data.listcate,function (index,category) {
                    if (category.type==1){
                        var $li = $('<li></li>')
                        var $div1 = $('<div class="zj" style="top:'+(-40*($int-1))+'px;"></div>')
                        var $div2 = $('<div class="zj_l"></div>')
                        $li.append('<a style="color: white" href="/CategoryList.html?level1='+category.id+'"><div class="fj">'+
                            '<span class="n_img"><span></span><img src="images/nav'+$int+'.png"/>'+'</span>'+
                            '<span class="fl">'+category.name+'</span>'+
                            '</div></a>')
                        $('.leftNav>ul').append($li)
                        $int = $int+1;
                        $.each(data.listcate,function(index,category2){
                            if (category.id==category2.parentid){
                                var $div3 = $('<div class="zj_l_c"></div>')
                                $div3.append('<a href="/CategoryList.html?level2='+category2.id+'"><h2>'+category2.name+'</h2></a>')
                                $div2.append($div3)
                                $div1.append($div2)
                                $li.append($div1)
                                $.each(data.listcate,function(index,category3){
                                    if (category2.id==category3.parentid){
                                        $div3.append('<a href="/CategoryList.html?level3='+category3.id+'">'+category3.name+'</a >'+'/')
                                    }
                                })
                            }
                        })
                    }
                })
                //楼层
                var index1 = 1;
                var indexr = 1;
                $.each(data.listcate,function(index,product1){
                    if(product1.type == 1){
                        var $divup = $('<div class = "i_t mar_10" >' +
                            '<span class ="floor_num" > '+(index1)+'F </span>' +
                            '<span class="fl">'+product1.name+'</span></div>');
                        var $divdown = $('<div class="content"></div>');
                        var $divleft = $('<div class="fresh_left"></div>');
                        var $divleftup = $('<div class="fre_ban"><div id="imgPlay1">\n' +
                            '<ul class="imgs" id="actor'+index1+'">\n' + '<li><a href="#"><img src="images/left_'+index1+'.jpg" width="211" height="286" /></a></li>\n' +
                            '<li><a href="#"><img src="images/left_'+index1+'.jpg" width="211" height="286" /></a></li>\n' +
                            '<li><a href="#"><img src="images/left_'+index1+'.jpg" width="211" height="286" /></a></li>\n' +
                            '</ul>\n' + '<div class="prevf">上一张</div>\n' + '<div class="nextf">下一张</div> \n' +
                            '</div></div></div>');
                        var $divleftdown = $('<div class="fresh_txt"></div>\n')
                        var $divleftdown_a=$('<div class="fresh_txt_c"></div>')
                        $.each(data.listcate,function(index,product2){
                            if(product2.type ==2 && product2.parentid == product1.id){
                                var $divleftdowna=$('<a href="javascript:void(0);">'+product2.name+'</a>');
                                $divleftdown.append($divleftdown_a.append($divleftdowna));
                            }
                        })
                        $divleft.append($divleftup).append($divleftdown);
                        var $divzhong = $('<div class="fresh_mid"></div>');
                        var $ulthing =$('<ul></ul>');
                        $divzhong.append($ulthing);
                        $.each(data.listthing,function(index,thing){
                            if(product1.id ==thing.categorylevel1id ){
                                var i = 0;
                                var $zhongli=$('<li>\n' + '\t<div class="name"><a href="/Product.html?id='+thing.id+'">'+thing.name+'</a></div>\n' +
                                    '<div class="price">\n' + '\t<font>￥<span>'+thing.price+'</span></font> &nbsp;' +
                                    '</div>\n' + '<div class="img"><a href="/Product.html?id='+thing.id+'"><img src="files/'+thing.filename+'" width="185" height="155" /></a></div>\n' + '</li>');
                                $ulthing.append($zhongli);
                                i=i+1;
                                if(i>=5){
                                    return;
                                }
                            }

                        })
                        var $divright = $('<div class="fresh_right">\n' + '<ul>\n' +
                            '<li><a href="#"><img src="images/right_'+indexr+'.jpg" width="260" height="220"/></a></li>\n' +
                            '<li><a href="#"><img src="images/right_'+(indexr+1)+'.jpg" width="260" height="220"/></a></li>\n' +
                            '</ul>\n' + '</div>')
                        indexr=indexr+2
                        $("#louceng").append($divup).append($divdown.append($divleft).append($divzhong).append($divright));
                        index1 = index1+1;

                    }
                    /**/
                })
            }
        })
    }
    init();
    $('.leftNav ul').on('mouseenter','li',function(){
        $(this).find(".fj").addClass("nuw");
        $(this).find(".zj").show();
    });

    $('.leftNav ul').on('mouseleave','li',function(){
        $(this).find(".fj").removeClass("nuw");
        $(this).find(".zj").hide();
    });

    //搜索
    $(".s_btn").click(function(){
        var $solr = $(".s_ipt").val();
        window.location.href="BrandList.html?solr="+$solr;0
    })

})